package com.mengchengnet.chaperonage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.mengchengnet.chaperonage.R;

import java.util.List;

/**
 * Created by Administrator on 16-3-8.
 */
public abstract class DropDownMenuAdapter<T> extends ArrayAdapter {

    private int resourceId;

    public DropDownMenuAdapter(Context context, int resource, List<T> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    public abstract String getId(int position);

    public abstract String getName(int position);

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        if (convertView == null) {
            view = LayoutInflater.from(getContext()).inflate(resourceId, null);
        } else {
            view = convertView;
        }

        TextView textView = (TextView) view.findViewById(R.id.tv_display_content);
        textView.setText(getName(position));

        return view;
    }
}
